using System;
using Slaks.Descriptions;

namespace Slaks.Filters
{

	/// <summary>
	/// ChemicalTermFilter - intended for parsing chemical terms with punctuation support
	/// </summary>
	[ModuleDescription("Chemical term filter supports saving punctuation marks","Slava Kisilevich and Marina Litvak")]
	public class ChemicalTermFilter : Slaks.Filters.AFilter
	{

		protected static readonly int EnglishCapitalLetterBegin = 0x41;
		protected static readonly int EnglishCapitalLetterEnd = 0x5a;

		protected static readonly int EnglishSmallLetterBegin = 0x61;
		protected static readonly int EnglishSmallLetterEnd = 0x7a;

		protected static readonly int EnglishLine = '-';

		public ChemicalTermFilter(){}

		/// <summary>
		/// All non english letters are considered white space.
		/// </summary>
		/// <param name="ch"></param>
		/// <returns></returns>
		public override bool IsWhiteSpace(char ch)
		{
			if (ch == EnglishLine) return false;
			if (ch < EnglishCapitalLetterBegin) return true;
			if (ch > EnglishCapitalLetterEnd && 
				ch < EnglishSmallLetterBegin) return true;
			if (ch > EnglishSmallLetterEnd) return true;
			return false;
		}

		public override bool DoSkipCharInTerm(char ch)
		{
			if (ch == '-') return true;
			return false;
		}

		/// <summary>
		/// Normalizes the character by lowering
		/// </summary>
		/// <param name="ch"></param>
		/// <returns></returns>
		public override char Normalize(char ch)
		{
			return char.ToLower(ch);
		}

		public override string ToString()
		{
			return "chemical term filter";
		}

	}
	
}
